package cn.wolfcode.luowowo.redis.service.impl;

import cn.wolfcode.luowowo.domain.UserInfo;
import cn.wolfcode.luowowo.redis.service.IUserInfoRedisService;
import cn.wolfcode.luowowo.redis.util.RedisKeys;
import cn.wolfcode.luowowo.util.Consts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

@Service
public class UserInfoRedisServiceImpl implements IUserInfoRedisService{
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Override
    public void sendVerifyCode(String phone, String code) {
        redisTemplate.opsForValue().set(RedisKeys.VERIFY_CODE.join(phone),code,RedisKeys.VERIFY_CODE.getTime(), TimeUnit.SECONDS);
    }

    @Override
    public String getVerifyCode(String phone) {
        return redisTemplate.opsForValue().get(RedisKeys.VERIFY_CODE.join(phone));
    }

    @Override
    public void setTonken(String token, String user) {
        redisTemplate.opsForValue().set(RedisKeys.VERIFY_TOKEN.join(token),user,RedisKeys.VERIFY_TOKEN.getTime(),TimeUnit.SECONDS);

    }

    @Override
    public String getUserByToken(String token) {
        String s = RedisKeys.VERIFY_TOKEN.join(token);
        return redisTemplate.opsForValue().get(s);
    }


}
